package ruralmanagementsystem.controller;

import io.jsonwebtoken.Claims;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import ruralmanagementsystem.mapper.LivestockMapper;
import ruralmanagementsystem.pojo.Livestock;
import ruralmanagementsystem.result.Result;
import ruralmanagementsystem.utils.JWTUtil;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/livestock")
@CrossOrigin
@Slf4j
public class LivestockController {

    @Autowired
    LivestockMapper livestockMapper;

    //增加某村户的家畜
    @PostMapping
    public Result addLivestock(@RequestBody Livestock livestock){
        livestockMapper.addLivestock(livestock);
        return Result.success();
    }

    //删除某村户的家畜
    @DeleteMapping("/{id}")
    public Result deleteLivestock(@PathVariable Integer id){
        livestockMapper.deleteLivestock(id);
        return Result.success();
    }

    //根据村户id查询旗下所有家畜
    @GetMapping
    public Result<List<Livestock>> getLivestockByHousehold(Integer id){
        List<Livestock> livestockList = livestockMapper.getLivestockByHousehold(id);
        return Result.success(livestockList);
    }

    //根据id查询某条家畜信息
    @GetMapping("/{id}")
    public Result<Livestock> getLivestockById(@PathVariable Integer id){
        Livestock livestock = livestockMapper.getLivestockById(id);
        return Result.success(livestock);
    }

    //根据id修改家畜信息
    @PutMapping
    public Result updateLivestockById(@RequestBody Livestock livestock){
        livestockMapper.updateLivestockLivestock(livestock);
        return Result.success();
    }
}

